package com.we823.cms.repository.service.beetl.tag;

import java.util.List;

import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import com.we823.cms.model.cms.PhotoLink;
import com.we823.cms.repository.service.cms.PhotoLinkService;

@Service("cms_photolinks")
@Scope("prototype")
public class PhotolinkListTag extends AbstractListTag {

	private static final String PARAM_CATEGORY = "category";
	@Autowired
	private PhotoLinkService photolinkService;
	
	@Override
	public void execute() {
		String category = getParam(PARAM_CATEGORY);
		List<PhotoLink> photoLinks = null;
		PageInfo<PhotoLink> photolinkPage;
		if (StringUtils.isEmpty(category)) {
			photolinkPage = photolinkService.findAll(pageRequest);
		}else {
			photolinkPage = photolinkService.findByCategory(category, pageRequest);
		}
		
		if (photolinkPage!=null) {
			photoLinks = photolinkPage.getList();
		}
		this.binds(photoLinks);
	}

	public PhotoLinkService getPhotolinkService() {
		return photolinkService;
	}

	public void setPhotolinkService(PhotoLinkService photolinkService) {
		this.photolinkService = photolinkService;
	}

	
}
